package icegps.com.pingdj.data.ble;

import com.clj.fastble.utils.HexUtil;

import timber.log.Timber;

/**
 * Created by 111 on 2017/11/22.
 */

public class WriteHelper {
    public static String CONNECT = "$ICEGPS,CONNECT,1";
    public static String DIS_CONNECT = "$ICEGPS,CONNECT,0";
    public static String TEST = "$ICEGPS,TESTMODE,1";
    public static String DIS_TEST = "$ICEGPS,TESTMODE,0";
    public static String SN = "$ICEGPS,FACTORY,SN,";
    public static String GET_DATA = "$ICEGPS,RAWDATA,1,";
    public static String DIS_DATA = "$ICEGPS,RAWDATA,0,";
    public static String GET_STATUS = "$ICEGPS,GETSTATUS";
    public static String GET_VER = "$ICEGPS,GETVER";
    public static String GET_RADIO = "$ICEGPS,GETRADIO";
    public static String SET_RADIO = "$ICEGPS,SETRADIO,";
    public static String SET_XYZ = "$ICEGPS,SETPOS,";
    public static String GETINSMODE = "$ICEGPS,GETINSMODE";
    public static String SETINSMODE = "$ICEGPS,SETINSMODE,";
    public static String AUTOBALANCE = "$ICEGPS,AUTOBALANCE,";
    public static String SATELLITE = "$ICEGPS,SATELLITE,";
    public static String GRADER = "$ICEGPS,GRADER,";
    public static String SET_OFFSET = "$ICEGPS,SETOFFSET,";
    public static String MODE = "$ICEGPS,MODE,";
    public static String RESTORE = "$ICEGPS,RESTORE";
    public static String SET_ACCURACY = "$ICEGPS,SETACCURACY,";
    public static String SET_BUCKETW = "$ICEGPS,SETBUCKETW,";
    public static String SET_ANTENNAP = "$ICEGPS,SETANTENNAP,";


    //key
    public static String KEY_RADIO = "$ICEGPS,RADIO";
    public static String KEY_OFFSET = "$ICEGPS,OFFSET";
    public static String KEY_MODE = "$ICEGPS,MODE";
    public static String KEY_VERSION = "$ICEGPS,VERSION";
    public static String KEY_ERROR = "$ICEGPS,ERROR*7F";
    public static String KEY_OK = "$ICEGPS,OK*23";
    public static String KEY_INSMODE = "$ICEGPS,INSMODE";
    public static String KEY_BALANCE = "$ICEGPS,BALANCE";
    public static String KEY_CONTROL = "$ICEGPS,CONTROL";
    public static String KEY_GRADER = "$ICEGPS,GRADER";
    public static String KEY_ACCURACY = "$ICEGPS,ACCURACY";
    public static String KEY_BUCKETW = "$ICEGPS,BUCKETW";
    public static String KEY_ANTENNAP = "$ICEGPS,ANTENNAP";



    public static String currentCMD;

    //计算校验值
    public static String addCheckSum(String s) {
        byte sum = 0;
        for (int i = 1; i < s.length(); i++) {
            sum ^= s.charAt(i);
        }
        return s + "*" + Integer.toHexString(sum) + "\r\n";
    }

    public static void write(String cmd) {
        currentCMD = cmd;
        String s = addCheckSum(cmd);
        Timber.e(s);
        byte[] bytes = s.getBytes();
        BleHelper.getInstance().write(bytes);
    }


}
